#include"Dlish.h"
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef struct{
    char *name;
    int age;
    float score;
}student;


typedef struct node{
    student *data;
    struct list_head list;
}queue;

queue *init_list(void){
    queue *head = malloc(sizeof(queue));
    if(head != NULL){
        INIT_LIST_HEAD(&head->list);
    }
    return head;
}

bool en_queue(queue *q, student *someone){
    if(q != NULL){
        queue *new = malloc(sizeof(queue));
        if(new != NULL){
            INIT_LIST_HEAD(&new->list);
            new->data = someone;
        }
        list_add_tail(&new->list, &q->list);
        return true;
    }
    return false;
}

bool out_queue(queue *q, student *psomeone){
    if(q != NULL){
        struct list_head *pos = q->list.next;
        list_del(pos);
        if(psomeone != NULL)
            psomeone = list_entry(pos, queue, list)->data;
        else
            free(list_entry(pos, queue, list));
        return true;
    }
    return false;
}

int main(int argc, char const *argv[])
{
    student zhangsan ={"张三", 20, 78};
    student lisi     ={"李四", 22, 86};
    student wangwu   ={"王五", 25, 66};
    student liuliu   ={"刘六", 21, 72};
    student tianqi   ={"田七", 23, 80};

    queue *head = init_list();
    en_queue(head, &zhangsan);
    en_queue(head, &lisi);
    en_queue(head, &wangwu);
    en_queue(head, &liuliu);
    en_queue(head, &tianqi);

    struct list_head *pos;
    list_for_each(pos, &head->list){
        student *someone = list_entry(pos, queue, list)->data;
        printf("姓名:%s\t年龄:%d\t\t分数:%.1f\n", 
            someone->name, someone->age, someone->score);
    }
    return 0;
}
